/**
 * @author Pawel Gadecki <pidzama@gmail.com>
 * 
 */
package spwodne;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import org.jdesktop.layout.GroupLayout;
import wydruk.Drukarnia;

public class OPodsWpl extends JFrame {

    public OPodsWpl() {
        initComponents();
        st = new String[3];
        sdf = new SimpleDateFormat("dd-MM-yyyy");
        String s = sdf.format(new Date());
        st = s.split("-");
        txtDay.setText(st[0]);
        txtMonth.setText(st[1]);
        txtYear.setText(st[2]);
        txtDay1.setText(st[0]);
        txtMonth1.setText(st[1]);
        txtYear1.setText(st[2]);
    }

    private void initComponents() {
        jPanel1 = new JPanel();
        jLabel1 = new JLabel();
        txtDay = new JTextField();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();
        txtMonth = new JTextField();
        txtYear = new JTextField();
        jPanel2 = new JPanel();
        jLabel4 = new JLabel();
        txtDay1 = new JTextField();
        jLabel5 = new JLabel();
        jLabel6 = new JLabel();
        txtMonth1 = new JTextField();
        txtYear1 = new JTextField();
        jButton1 = new JButton();
        jButton2 = new JButton();
        setDefaultCloseOperation(2);
        setTitle("Wyszukiwanie wp\u0142at");
        jPanel1.setBorder(BorderFactory.createTitledBorder("Od"));
        jLabel1.setText("Data");
        txtDay.setText("12");
        jLabel2.setText("-");
        jLabel3.setText("-");
        txtMonth.setText("12");
        txtYear.setText("2004");
        txtYear.setNextFocusableComponent(txtDay1);
        GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jLabel1).addPreferredGap(0).add(txtDay, -2, -1, -2).add(4, 4, 4).add(jLabel2).add(4, 4, 4).add(txtMonth, -2, -1, -2).add(3, 3, 3).add(jLabel3).add(3, 3, 3).add(txtYear, -2, -1, -2).addContainerGap(-1, 32767)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout.createParallelGroup(3).add(jLabel1).add(txtDay, -2, -1, -2).add(jLabel2).add(txtMonth, -2, -1, -2).add(jLabel3).add(txtYear, -2, -1, -2)).addContainerGap(14, 32767)));
        jPanel2.setBorder(BorderFactory.createTitledBorder("Do"));
        jLabel4.setText("Data");
        txtDay1.setText("12");
        jLabel5.setText("-");
        jLabel6.setText("-");
        txtMonth1.setText("12");
        txtYear1.setText("2004");
        GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(1).add(jPanel2Layout.createSequentialGroup().addContainerGap().add(jLabel4).addPreferredGap(0).add(txtDay1, -2, -1, -2).add(4, 4, 4).add(jLabel5).add(4, 4, 4).add(txtMonth1, -2, -1, -2).add(3, 3, 3).add(jLabel6).add(3, 3, 3).add(txtYear1, -2, -1, -2).addContainerGap(-1, 32767)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(1).add(jPanel2Layout.createSequentialGroup().addContainerGap().add(jPanel2Layout.createParallelGroup(3).add(jLabel4).add(txtDay1, -2, -1, -2).add(jLabel5).add(txtMonth1, -2, -1, -2).add(jLabel6).add(txtYear1, -2, -1, -2)).addContainerGap(14, 32767)));
        jButton1.setText("OK");
        jButton1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
            final OPodsWpl this$0;
            

            {
                this$0 = OPodsWpl.this;
            //super();
            }
        });
        jButton2.setText("anuluj");
        jButton2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
            final OPodsWpl this$0;
            

            {
                this$0 = OPodsWpl.this;
            //super();
            }
        });
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().addContainerGap().add(layout.createParallelGroup(2, false).add(1, jPanel1, -1, -1, 32767).add(1, jPanel2, -1, -1, 32767)).addPreferredGap(0).add(layout.createParallelGroup(1, false).add(jButton1, -1, -1, 32767).add(jButton2, -1, -1, 32767)).addContainerGap(-1, 32767)));
        layout.setVerticalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().add(layout.createParallelGroup(1).add(2, layout.createSequentialGroup().addContainerGap().add(jButton1).addPreferredGap(0, 7, 32767).add(jButton2)).add(jPanel1, -2, -1, -2)).addPreferredGap(0).add(jPanel2, -2, -1, -2).addContainerGap(-1, 32767)));
        pack();
    }

    private void jButton2ActionPerformed(ActionEvent evt) {
        dispose();
    }

    private void jButton1ActionPerformed(ActionEvent evt) {
        try {
            String s = (new StringBuilder()).append(txtDay.getText()).append("-").append(txtMonth.getText()).append("-").append(txtYear.getText()).toString();
            String s2 = (new StringBuilder()).append(txtDay1.getText()).append("-").append(txtMonth1.getText()).append("-").append(txtYear1.getText()).toString();
            Date d = sdf.parse(s);
            Date d2 = sdf.parse(s2);

            Drukarnia.getInstance().drukujSpolki(MTSpolek.getLSpolek(), d, d2, "xml/wplaty_od_do.xml");

            //Preview p = new Preview(new DokWplOdDo(d, d2));
            //p.setVisible(true);
            dispose();
        } catch (ParseException exc) {
            JOptionPane.showMessageDialog(this, "B\u0142ad podczas wprowadzania daty - (sprawdz czy pola daty zawieraja odpowiednie warto\u015B\u0107i)");
        } catch (Exception eex) {
            JOptionPane.showMessageDialog(this, "Błąd tworzenia wydruku");
            eex.printStackTrace();
        }
    }
    private SimpleDateFormat sdf;
    private String st[];
    private JButton jButton1;
    private JButton jButton2;
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JLabel jLabel4;
    private JLabel jLabel5;
    private JLabel jLabel6;
    private JPanel jPanel1;
    private JPanel jPanel2;
    private JTextField txtDay;
    private JTextField txtDay1;
    private JTextField txtMonth;
    private JTextField txtMonth1;
    private JTextField txtYear;
    private JTextField txtYear1;
}
